package com.msh.artascope.web.common.bean;

import com.msh.artascope.client.def.ArtascopeDef;
import  com.msh.artascope.interfaces.IAccountGet;
import  com.msh.artascope.interfaces.ILoginAccount;
import com.msh.frame.web.util.HttpServletRequestUtil;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.StringUtils;

public class GatewayAccountGat implements IAccountGet {

  @Override
  public ILoginAccount getLoginAccount() {
    HttpServletRequest request = HttpServletRequestUtil.getCurrentRequest();
    String userId = request.getHeader(ArtascopeDef.GATEWAY_USER_ID);
    if(StringUtils.isEmpty(userId)){
      return null;
    }
    String account = request.getHeader(ArtascopeDef.GATEWAY_ACCOUNT);
    String tenantId = request.getHeader(ArtascopeDef.GATEWAY_TENANT_ID);
    return new ILoginAccount() {
      @Override
      public Long getId() {
        return Long.valueOf(userId);
      }

      @Override
      public String getAccount() {
        return account;
      }

      @Override
      public Long getTenantId() {
        return Long.valueOf(tenantId);
      }
    };
  }
}
